package com.linkoog.devtools.maven.dependency_folding;

import com.intellij.openapi.components.PersistentStateComponent;
import com.intellij.openapi.components.State;
import com.intellij.openapi.components.Storage;
import com.intellij.openapi.project.Project;
import com.intellij.util.xmlb.XmlSerializerUtil;
import com.linkoog.devtools.maven.version_show.persistent.MavenPluginSettings;
import lombok.Getter;
import lombok.Setter;
import org.jetbrains.annotations.NotNull;

/**
 * Supports storing the application settings in a persistent way.
 * The [State] and [Storage] annotations define the name of the data and the file name where
 * these persistent application settings are stored.
 */
@Setter
@Getter
@State(name = "com.trianguloy.mavendependencycollapse.DependencyFoldsState", storages = {@Storage("DependencyFoldPlugin.xml")})
public final class SettingsState implements PersistentStateComponent<SettingsState> {
    public static final String DEFAULT_COLLAPSED_TEXT = "${scope|[%s] }${groupId||{no groupId\\}} : ${artifactId||{no artifactId\\}}${version| : %s}";
    public static final boolean DEFAULT_COLLAPSED_BY_DEFAULT = true;

    private String collapsedText = DEFAULT_COLLAPSED_TEXT;
    private boolean collapsedByDefault = DEFAULT_COLLAPSED_BY_DEFAULT;

    public static SettingsState getInstance(@NotNull Project project) {
        return project.getService(SettingsState.class);
    }

    @Override
    public SettingsState getState() {
        return this;
    }

    @Override
    public void loadState(SettingsState state) {
        XmlSerializerUtil.copyBean(state, this);
    }


}
